package com.hdaccp.shuiguoD.controller;

import com.hdaccp.shuiguoD.dao.HouseinfoDao;
import com.hdaccp.shuiguoD.pogo.HouseCangKuBean;
import com.hdaccp.shuiguoD.pogo.HouseDanWeiBean;
import com.hdaccp.shuiguoD.pogo.HouseJiaGeBean;
import com.hdaccp.shuiguoD.pogo.HouseLeiBieBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/house")
@Scope("prototype")
public class HouseInfoController {
    @Autowired
    private HouseinfoDao houseinfoDao  ;

    @RequestMapping("/queryGroupDanWei")
    @ResponseBody
    public Map<String,List<Object>> queryGroupDanWei(){
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Map<String,List<Object>> map = new HashMap<>() ;
        List<HouseDanWeiBean> list = houseinfoDao.queryGroupDanWei() ;
        List<Object> list1 = new ArrayList<>() ;
        List<Object> list2 = new ArrayList<>() ;

        for(HouseDanWeiBean bean : list){
            list1.add(bean.getDname()) ;
            list2.add(bean.getDanweicount()) ;
        }

        map.put("dw",list1) ;
        map.put("dwc",list2) ;

        return map ;
    }


    @RequestMapping("/queryGroupLeiBie")
    @ResponseBody
    public Map<String,List<HouseLeiBieBean>> queryGroupLeiie(){
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        List<HouseLeiBieBean> list = houseinfoDao.queryGroupLeiBie() ;
        Map<String,List<HouseLeiBieBean>> map = new HashMap<>() ;
        map.put("t",list) ;

        return map ;
    }


    @RequestMapping("/queryGroupJiaGe")
    @ResponseBody
    public List<HouseJiaGeBean> queryGroupJiaGe(){
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        List<HouseJiaGeBean> list = houseinfoDao.queryGroupJiaGe() ;

        return list ;
    }


    @RequestMapping("/queryGroupCangKu")
    @ResponseBody
    public Map<String,List<Object>> queryGroupCangKu(){
        Map<String,List<Object>> map = new HashMap<>();
        List<HouseCangKuBean> list = houseinfoDao.queryGroupCangKu();
        List<Object> list1 = new ArrayList<>();
        List<Object> list2 = new ArrayList<>();

        for (HouseCangKuBean bean : list){
            list1.add(bean.getCname());
            list2.add(bean.getCangkucount());
        }

        map.put("ck",list1);
        map.put("ckc",list2);
        return map;
    }

}
